from django.urls import path
from django.contrib.auth import views as auth_views
from .views import (
    HomeView,
    ServerListView,
    ServerCreateView,
    ServerDeleteView,
    CDNDomainListView,
    CDNDomainCreateView,
    CDNDomainDeleteView,
    RequestUrlListView,
    RequestUrlCreateView,
    RequestUrlDeleteView,
    RequestUrlBatchDeleteView,
    AutoTaskListView,
    AutoTaskCreateView,
    AutoTaskDeleteView,
    AutoTaskDetailView,
    ManualPreheatCreateView,
    ManualPreheatStatusView,
    CheckPreheatStatusView,
    RestartSchedulerView,
    GetResultDetailView,
    UserListView,
    UserCreateView,
    UserUpdateView,
    UserDeleteView,
    UserPasswordChangeView
)

app_name = 'preheat'

urlpatterns = [
    # 认证相关
    path('login/', auth_views.LoginView.as_view(template_name='preheat/login.html'), name='login'),
    path('logout/', auth_views.LogoutView.as_view(next_page='preheat:home'), name='logout'),
    # 用户管理
    path('users/', UserListView.as_view(), name='user_list'),
    path('users/create/', UserCreateView.as_view(), name='user_create'),
    path('users/<int:pk>/update/', UserUpdateView.as_view(), name='user_update'),
    path('users/<int:pk>/delete/', UserDeleteView.as_view(), name='user_delete'),
    path('users/<int:pk>/change-password/', UserPasswordChangeView.as_view(), name='user_password_change'),
    # 主页
    path('', HomeView.as_view(), name='home'),
    
    # 服务器管理
    path('servers/', ServerListView.as_view(), name='server_list'),
    path('servers/create/', ServerCreateView.as_view(), name='server_create'),
    path('servers/<int:pk>/delete/', ServerDeleteView.as_view(), name='server_delete'),
    
    # CDN域名管理
    path('cdn-domains/', CDNDomainListView.as_view(), name='cdn_domain_list'),
    path('cdn-domains/create/', CDNDomainCreateView.as_view(), name='cdn_domain_create'),
    path('cdn-domains/<int:pk>/delete/', CDNDomainDeleteView.as_view(), name='cdn_domain_delete'),
    
    # 请求地址管理
    path('request-urls/', RequestUrlListView.as_view(), name='request_url_list'),
    path('request-urls/create/', RequestUrlCreateView.as_view(), name='request_url_create'),
    path('request-urls/<int:pk>/delete/', RequestUrlDeleteView.as_view(), name='request_url_delete'),
    path('request-urls/batch-delete/', RequestUrlBatchDeleteView.as_view(), name='request_url_batch_delete'),
    
    # 自动任务管理
    path('auto-tasks/', AutoTaskListView.as_view(), name='auto_task_list'),
    path('auto-tasks/create/', AutoTaskCreateView.as_view(), name='auto_task_create'),
    path('auto-tasks/<int:pk>/delete/', AutoTaskDeleteView.as_view(), name='auto_task_delete'),
    path('auto-tasks/<int:pk>/detail/', AutoTaskDetailView.as_view(), name='auto_task_detail'),
    
    # 手动预热
    path('manual-preheat/create/', ManualPreheatCreateView.as_view(), name='manual_preheat_create'),
    path('manual-preheat/<uuid:pk>/status/', ManualPreheatStatusView.as_view(), name='manual_preheat_status'),
    path('manual-preheat/<uuid:pk>/check-status/', CheckPreheatStatusView.as_view(), name='check_preheat_status'),
    
    # 调度器管理
    path('scheduler/restart/', RestartSchedulerView.as_view(), name='restart_scheduler'),
    
    # 执行结果详情
    path('get_result_detail/<int:result_id>/', GetResultDetailView.as_view(), name='get_result_detail'),
    
    # 为了确保login和logout可以被全局访问，这里添加不带app_name前缀的路由
    path('accounts/login/', auth_views.LoginView.as_view(template_name='preheat/login.html'), name='login'),
    path('accounts/logout/', auth_views.LogoutView.as_view(next_page='preheat:home'), name='logout'),
]